package com.creditharmony.car.loan.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.creditharmony.car.common.base.service.impl.BaseServiceImpl;
import com.creditharmony.car.common.common.vo.requestvo.CarLoanFeeRequestVo;
import com.creditharmony.car.common.exception.UserException;
import com.creditharmony.car.common.exception.UserExceptionConstants;
import com.creditharmony.car.common.utils.UuidUtil;
import com.creditharmony.car.loan.dao.CarLoanFeeDao;
import com.creditharmony.car.loan.entity.CarLoanFeeEntity;
import com.creditharmony.car.loan.service.CarLoanFeeService;
/**
 * 
 * @Class Name CarLoanFeeServiceImpl
 * @author zqa
 * @Create In 2018年2月2日
 */
@Service
public class CarLoanFeeServiceImpl extends BaseServiceImpl<CarLoanFeeEntity> implements CarLoanFeeService {
    private static final Logger logger = LoggerFactory.getLogger(CarLoanFeeServiceImpl.class);
    @Autowired
    private CarLoanFeeDao carLoanFeeDao;
    
    @Override
    public void saveCarLoanFee(CarLoanFeeRequestVo vo) {
        CarLoanFeeEntity entity = new CarLoanFeeEntity();
        try {
            BeanUtils.copyProperties(vo, entity);
            entity.setId(UuidUtil.getUUID());
            carLoanFeeDao.insertSelective(entity);
        }catch (BeansException e) {
            logger.error("CarLoanFeeEntity对象拷贝属性值抛出异常",e);
            throw new UserException(UserExceptionConstants.BEAN_COPY_ERROR,e);
        }catch(Exception e){
            logger.error(UserExceptionConstants.DB_SYSTEM_ERROR, e);
            throw new UserException(UserExceptionConstants.DB_SYSTEM_ERROR, e);
        }
        
    }

    @Override
    public void updateCarloanFee(CarLoanFeeRequestVo vo) {
        CarLoanFeeEntity entity = new CarLoanFeeEntity();
        try {
            BeanUtils.copyProperties(vo, entity);
            carLoanFeeDao.updateCarloanFee(entity);
        }catch (BeansException e) {
            logger.error("CarLoanFeeEntity对象拷贝属性值抛出异常",e);
            throw new UserException(UserExceptionConstants.BEAN_COPY_ERROR,e);
        }catch(Exception e){
            logger.error(UserExceptionConstants.DB_SYSTEM_ERROR, e);
            throw new UserException(UserExceptionConstants.DB_SYSTEM_ERROR, e);
        }
        
    }
 
}
